/*
 * 版权所有 (c) 华为技术有限公司 2022-2022
 */
package com.huawei.cameratest.data;

import android.hardware.camera2.CameraCharacteristics;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class CameraCharacteristicsEx {
    public static CameraCharacteristics.Key ZOOM_RATIO_RANGE  = instance("com.camera.device.capabilities.zoomRange", Byte[].class);
    public static CameraCharacteristics.Key CAMERA_DEVICE_TYPE  = instance("com.camera.device.capabilities.cameraDeviceType", Byte.class);
    public static CameraCharacteristics.Key SUPPORTED_MIRROR_MODE = instance("com.camera.device.capabilities.mirrorModeSupported", Byte.class);
    public static CameraCharacteristics.Key AI_SUPPORTED = instance("com.camera.device.capabilities.skeletonDetectionSupported", Byte.class);
    public static CameraCharacteristics.Key ISPVERSION = instance("com.camera.device.capabilities.queryIspVer", byte[].class);
    public static CameraCharacteristics.Key QUERYISP_MODE = instance("com.camera.device.capabilities.queryIspUpdateMode", Integer.class);
    public static CameraCharacteristics.Key ODM_CAP = instance("com.camera.device.capabilities.odmCap", byte[].class);
    public static CameraCharacteristics.Key HAL_CUSTOM_CAMERA_H264_AVAILABLE_STREAM_CONFIGURATIONS = instance("com.camera.device.capabilities.h264AvailableStreamConfigurations", Integer[].class);
    public static CameraCharacteristics.Key HAL_CUSTOM_CAMERA_H264_AVAILABLE_MIN_FRAME_DURATIONS = instance("com.camera.device.capabilities.h264AvailableMinFrameDurations", Long[].class);
    public static CameraCharacteristics.Key HAL_CUSTOM_CAMERA_H264_AVAILABLE_STALL_DURATIONS = instance("com.camera.device.capabilities.h264AvailableStallDurations", Long[].class);
    public static CameraCharacteristics.Key HAL_CUSTOM_CAMERA_H265_AVAILABLE_STREAM_CONFIGURATIONS = instance("com.camera.device.capabilities.h265AvailableStreamConfigurations", Integer[].class);
    public static CameraCharacteristics.Key HAL_CUSTOM_CAMERA_H265_AVAILABLE_MIN_FRAME_DURATIONS = instance("com.camera.device.capabilities.h265AvailableMinFrameDurations", Long[].class);
    public static CameraCharacteristics.Key HAL_CUSTOM_CAMERA_H265_AVAILABLE_STALL_DURATIONS = instance("com.camera.device.capabilities.h265AvailableStallDurations", Long[].class);
    public static CameraCharacteristics.Key PICTURE_ROTATION_BY_HAL_SUPPORTED = instance("com.camera.device.capabilities.pictureRotationByHalSupported", Integer.class);
    public static CameraCharacteristics.Key H264_SVC_MODES = instance("com.camera.device.capabilities.h264svcModes", Integer[].class);
    public static CameraCharacteristics.Key PREVIEW_VIA_VO_SUPPORTED = instance("com.camera.device.capabilities.previewViaVoSupported", Byte.class);

    private static CameraCharacteristics.Key instance(String value, Class classes) {
        try {
            Class cla = Class.forName("android.hardware.camera2.CameraCharacteristics$Key");
            Constructor constructor = cla.getConstructor(String.class, Class.class);
            CameraCharacteristics.Key key = (CameraCharacteristics.Key) constructor.newInstance(value, classes);
            return key;
        } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
            e.printStackTrace();
            return null;
        }
    }
}
